import Vue from 'vue'
import Router from 'vue-router'
import Login from '../view/Login.vue'
import Home from '../view/Home.vue'
import Welcom from'../view/Welcom.vue'
import Users from '../components/users/UserList.vue'
// import GoodsList from '../components/goods/GoodsList.vue'
import Right from '../components/power/Right.vue'
import Roles from '../components/power/Roles.vue'
import Categories from '../components/goods/Cate.vue'
import Params from '../components/goods/Params.vue'
import GoodsList from '../components/goods/List.vue'
import Add from '../components/goods/Add.vue'
import OrderList from '../components/order/List.vue'
import Reports from '../components/reports/Reports.vue'
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      redirect:'/login'
    },
    {
      path:'/login',
      name:'Login',
      component:Login
    },
    {
      path:'/home',
      name:'Home',
      redirect:'/welcom',
      component:Home,children:[
        {
          path:'/welcom',
          component:Welcom
        },
        {
          path:'/users',
          name:'Users',
          component:Users
        },
        {
          path:'/goods',
          name:'GoodsList',
          component:GoodsList
        },
        {
          path:'/categories',
          name:'Categories',
          component:Categories
        },
        {
          path:'/params',
          name:'Params',
          component:Params
        },
        {
          path:'/goods/add',
          name:'Add',
          component:Add
        },
        {
          path:'/rights',
          name:'Right',
          component:Right
        },
        {
          path:'/roles',
          name:'Roles',
          component:Roles
        },
        {
          path:'/orders',
          name:'OrderList',
          component:OrderList
        },
        {
          path:'/reports',
          name:'Reports',
          component:Reports
        },
      ]
    },
    

  ]
});
// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to将要访问的路径
  if(to.path === '/login')return next()
  // form代表从哪个函数跳转而来
  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login')
  // next是一个函数，代表放行
  // next(),next('/login')强制跳转
  next()
})
export default router 
